package com.ymx.sdk.util;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.WindowManager;

import com.ymx.sdk.widget.PullToRefreshView.PullToRefreshListView;

/**
 * Created by zhilian-2 on 2015/10/16.
 */
public class DeviceUtils {

    public static int screenWidth;//当前手机屏幕的宽度(px)
    public static int screenHeight;//当前手机屏幕的高度(px)
    /**
     * 获取屏幕的宽度
     * @param context
     * @return
     */
    public static int getScreenWidth(Context context){
        if (screenWidth != 0) return screenWidth;
        if (context == null) return 720;
        WindowManager manager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics dm=new DisplayMetrics();
        manager.getDefaultDisplay().getMetrics(dm);
        screenWidth = dm.widthPixels;
        screenHeight = dm.heightPixels;
        return screenWidth;
    }

    /**
     * 获取屏幕的高度
     * @param context
     * @return
     */
    public static int getScreenHeight(Context context){
        if (screenHeight != 0) return screenHeight;
        if (context == null) return 1280;
        WindowManager manager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics dm=new DisplayMetrics();
        manager.getDefaultDisplay().getMetrics(dm);
        screenWidth = dm.widthPixels;
        screenHeight = dm.heightPixels;
        return screenHeight;
    }
}
